/*
 * 
 *
 *
 */
package com.hboxs.asl.dao.impl;

import com.hboxs.asl.dao.GlobalConfigDao;
import com.hboxs.asl.entity.GlobalConfig;
import org.springframework.stereotype.Repository;

import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;

/**
 * Dao - 全局设定
 */
@Repository("globalConfigDaoImpl")
public class GlobalConfigDaoImpl extends BaseDaoImpl<GlobalConfig, Long> implements GlobalConfigDao {

    @Override
    public GlobalConfig getUniqueness() {
        String jpql = "select globalConfig from GlobalConfig globalConfig ";
        GlobalConfig globalConfig = null;
        try {
            globalConfig = entityManager.createQuery(jpql, GlobalConfig.class).setFlushMode(FlushModeType.COMMIT).setMaxResults(1).getSingleResult();

        } catch (NoResultException e) {
            globalConfig = new GlobalConfig();
            this.persist(globalConfig);
        }
        return globalConfig;
    }

}
